package com.starview.star.compiler.util;

/**
 * To force a way around a restriction in Java's anonymous classes
 * 
 * @author fgm
 * 
 * @param <T>
 */
@SuppressWarnings("serial")
public class Wrapper<T> implements PrettyPrintable
{
  private T el;

  public Wrapper(T el)
  {
    this.set(el);
  }

  public static <T> Wrapper<T> create(T el)
  {
    return new Wrapper<T>(el);
  }

  public void set(T el)
  {
    this.el = el;
  }

  public T get()
  {
    return el;
  }

  public boolean isEmpty()
  {
    return el == null;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append("{");
    if (el instanceof PrettyPrintable) {
      ((PrettyPrintable) el).prettyPrint(disp);
    } else if (el != null)
      disp.append(el.toString());
    else
      disp.append("null");
    disp.append("}");
  }

  @Override
  public String toString()
  {
    return PrettyPrintDisplay.toString(this);
  }
}
